package com.caiyouxi.pay.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.pay.mapper.PaymentConfigMapper;
import com.caiyouxi.pay.model.PaymentConfig;
import com.caiyouxi.pay.service.PaymentConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PaymentConfigServiceImpl extends BaseService implements PaymentConfigService {
    @Autowired
    private PaymentConfigMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData deleteByPrimaryKey(PaymentConfig bean) {
        return success(mapper.deleteByPrimaryKey(bean.getId()));
    }

    @Override
    public ResData insert_pay(PaymentConfig bean) {
        return success(mapper.insert_pay(bean));
    }

    @Override
    public ResData select_pay(PaymentConfig bean) {
        return success(mapper.select_pay(bean.getId()));
    }

    @Override
    public ResData update_pay(PaymentConfig bean) {
        return success(mapper.update_pay(bean));
    }

    @Override
    public ResData select_pay_list(PaymentConfig bean) {
        Integer page_list = Integer.parseInt(redisService.get("sys.pagesize").toString());
        QueryParams pageList = new QueryParams();
        if (bean.getPage_size() == 0){
            bean.setPage_size(page_list);
        }
        pageList.setPage(bean.getPage());
        pageList.setPage_size(bean.getPage_size());
        pageList.setList(mapper.select_pay_list(bean));
        pageList.setTotal(mapper.select_pay_count(bean));
        return success(pageList);
    }

}
